package com.gesee.zyspps.activity;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;

import com.gesee.zys.R;
import com.gesee.zyspps.ZSApplication;
import com.gesee.zyspps.adapter.FswAdapter;
import com.gesee.zyspps.db.CmsFeature;
import com.gesee.zyspps.db.CmsLine;
import com.gesee.zyspps.db.CmsPoints;
import com.gesee.zyspps.db.CmsPointsDao.Properties;
import com.gesee.zyspps.utils.LogUtil;
import com.gesee.zyspps.utils.StringUtil;
import com.gesee.zyspps.utils.ToastUtil;

/**
 * 
 * @ClassName: UpdatePointActivity
 * @Description: TODO(修改点属性)
 * @author fujianxiong
 * @date 2015年8月28日 下午4:41:18
 *
 */
public class UpdatePointActivity extends BaseActivity implements OnClickListener
{
    private Button btnAccept, btnCancel;
    private EditText et_gdbh;// 管点编号
    private boolean flag = false;
    private boolean flag1 = false;
    private boolean flag2 = false;
    
//    private CheckBox cb_kj;// 是否可见
    private EditText et_tezheng;// 特征
    private EditText et_fsw;// 附属物
    private EditText et_jdms;// 井底埋深
    private EditText et_jggg;// 井盖规格
    private EditText et_jgcz;// 井盖材质
    // private EditText et_jgcc;// 井盖尺寸
    private EditText et_jtsd;// 井桶深度
    private EditText et_jscc;// 井室尺寸
    private EditText et_xzuobiao;// X坐标
    private EditText et_yzuobiao;// Y坐标
    private EditText et_qsdw;// 权属单位
    private EditText et_dlmc;// 道路名称
    private EditText et_bz;// 备注
    private EditText et_ydqk;// 淤堵情况

    private Spinner sp_tezheng;// 特征
    private Spinner sp_fsw;// 附属物
    private Spinner sp_jgcz;// 井盖材质
    private Spinner sp_qsdw;// 权属单位
    private Spinner sp_ydqk;// 淤堵情况

    private String[] tzItems;
    private String[] fswItems;
    private String[] jgczItems;
    private String[] qsdwItems;
    private String[] ydqkItems;
    
    private LinearLayout ll_dlts;// 电缆条数
    private LinearLayout ll_yyks;// 已用孔数
    private LinearLayout ll_zks;// 总孔数
    
    private EditText et_dlts;
    private EditText et_yyks;
    private EditText et_zks;

    private FswAdapter fswAdapter1, tzAdapter1,jgczAdapter1,qsdwAdapter1,ydqkAdapter1;

    private List<CmsPoints> pointsList;

    private ArrayAdapter<String> tzAdapter;
    private ArrayAdapter<String> fswAdapter;
    private ArrayAdapter<String> jgczAdapter;
    private ArrayAdapter<String> qsdwAdapter;
    private ArrayAdapter<String> ydqkAdapter;
    private EditText et_jslx,et_tcsss,et_tcsns,et_jcjdj,et_jcjzpbh;
    private String mapNo;// 管点编号
    private String D_X; // X坐标
    private String D_Y;// Y坐标
    private String expNo,pCode;
    private double latitude, longitude;
    private long id;
    private int mapNoNum;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_point);
        findView();
        initView();
    }

    private void findView()
    {
        btnAccept = (Button) findViewById(R.id.btnAccept);
        btnCancel = (Button) findViewById(R.id.btnCancel);
        et_gdbh = (EditText) findViewById(R.id.et_gdbh);
//        cb_kj = (CheckBox) findViewById(R.id.cb_kj);
        et_tezheng = (EditText) findViewById(R.id.et_tezheng);
        et_fsw = (EditText) findViewById(R.id.et_fsw);
        et_jdms = (EditText) findViewById(R.id.et_jdms);
        et_jggg = (EditText) findViewById(R.id.et_jggg);
        et_jgcz = (EditText) findViewById(R.id.et_jgcz);
        et_jtsd = (EditText) findViewById(R.id.et_jtsd);
        et_jscc = (EditText) findViewById(R.id.et_jscc);
        et_xzuobiao = (EditText) findViewById(R.id.et_xzuobiao);
        et_yzuobiao = (EditText) findViewById(R.id.et_yzuobiao);
        et_qsdw = (EditText) findViewById(R.id.et_qsdw);
        et_dlmc = (EditText) findViewById(R.id.et_dlmc);
        et_bz = (EditText) findViewById(R.id.et_bz);
        et_ydqk = (EditText) findViewById(R.id.et_ydqk);
        et_jslx = (EditText) findViewById(R.id.et_jslx);
        et_tcsss = (EditText) findViewById(R.id.et_tcsss);
        et_tcsns = (EditText) findViewById(R.id.et_tcsns);
        et_jcjdj = (EditText) findViewById(R.id.et_jcjdj);
        et_jcjzpbh = (EditText) findViewById(R.id.et_jcjzpbh);
        
        ll_dlts = (LinearLayout) findViewById(R.id.ll_dlts);
        ll_yyks = (LinearLayout) findViewById(R.id.ll_yyks);
        ll_zks = (LinearLayout) findViewById(R.id.ll_zks);
        et_dlts = (EditText) findViewById(R.id.et_dlts);
        et_yyks = (EditText) findViewById(R.id.et_yyks);
        et_zks = (EditText) findViewById(R.id.et_zks);

        sp_tezheng = (Spinner) findViewById(R.id.sp_tezheng);
        sp_fsw = (Spinner) findViewById(R.id.sp_fsw);
        sp_jgcz = (Spinner) findViewById(R.id.sp_jgcz);
        sp_qsdw = (Spinner) findViewById(R.id.sp_qsdw);
        sp_ydqk = (Spinner) findViewById(R.id.sp_ydqk);
    }

    private void initView()
    {
        getMyIntent();
        setOnclick();
        setSpinner();

    }

    private void setOnclick()
    {
        btnAccept.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
    }

    private void getMyIntent()
    {
        Intent intent = getIntent();
        D_X = intent.getStringExtra("D_X");
        D_Y = intent.getStringExtra("D_Y");
        mapNo = intent.getStringExtra("mapNo");
        setData();
    }

    private void setData()
    {
        String dbName = ZSApplication.getInstance().getConfig("newDBName");

        latitude = Double.parseDouble(D_X);
        longitude = Double.parseDouble(D_Y);
        
        pointsList = ZSApplication.getDaoSession(dbName).getCmsPointsDao().queryBuilder().where(Properties.D_X.eq(latitude), Properties.D_Y.eq(longitude)).build().list();

        for (int i = 0; i < pointsList.size(); i++)
        {
            id = pointsList.get(i).getId();
            expNo = pointsList.get(i).getExpNO();
            mapNoNum = pointsList.get(i).getMapNoNum();
            pCode = pointsList.get(i).getPCode();
            et_gdbh.setText(pointsList.get(i).getExpNO());
            et_tezheng.setText(pointsList.get(i).getFeature());
            et_fsw.setText(pointsList.get(i).getSubsid());
            et_jdms.setText(pointsList.get(i).getWDeep());
            et_jggg.setText(pointsList.get(i).getMtype());
            et_jgcz.setText(pointsList.get(i).getWcover());
            et_jtsd.setText(pointsList.get(i).getWdepth());
            et_jscc.setText(pointsList.get(i).getHsize());
            et_xzuobiao.setText(pointsList.get(i).getD_X() + "");
            et_yzuobiao.setText(pointsList.get(i).getD_Y() + "");
            et_qsdw.setText(pointsList.get(i).getBCode());
            et_dlmc.setText(pointsList.get(i).getRoadName());
            et_bz.setText(pointsList.get(i).getRemark());
            et_ydqk.setText(pointsList.get(i).getSblock());
           /* et_dlts.setText(pointsList.get(i).getCableLines());
            et_yyks.setText(pointsList.get(i).getUseHole());
            et_zks.setText(pointsList.get(i).getTotalHole());*/
        }
        
//        if ("GD".equals(pCode)||"LD".equals(pCode)||"XH".equals(pCode)||"DC".equals(pCode)||"DX".equals(pCode)||"LT".equals(pCode)||"YD".equals(pCode)||"TT".equals(pCode)||"DS".equals(pCode)||"GB".equals(pCode)||"JK".equals(pCode)||"DT".equals(pCode)||"JG".equals(pCode))
//        {
//            ll_dlts.setVisibility(View.VISIBLE);
//            ll_yyks.setVisibility(View.VISIBLE);
//            ll_zks.setVisibility(View.VISIBLE);
//        }
        
    }

    private void setSpinner()
    {
        tzItems = getResources().getStringArray(R.array.tz);
        fswItems = getResources().getStringArray(R.array.fsw);
        jgczItems = getResources().getStringArray(R.array.jgcz);
        qsdwItems = getResources().getStringArray(R.array.qsdw);
        ydqkItems = getResources().getStringArray(R.array.ydqk);

        tzAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, tzItems);
        tzAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp_tezheng.setAdapter(tzAdapter);

        tzAdapter1 = new FswAdapter(this);
        List<CmsFeature> tzlist = ZSApplication.getDaoSession("zyspps-db").getCmsFeatureDao().queryBuilder()
                .where(com.gesee.zyspps.db.CmsFeatureDao.Properties.SubCodes.like("%" + mapNo + "%"), com.gesee.zyspps.db.CmsFeatureDao.Properties.FiledName.eq("特征"))
                .orderAsc(com.gesee.zyspps.db.CmsFeatureDao.Properties.Sort).list();
        sp_tezheng.setAdapter(tzAdapter1);
        tzAdapter1.addData(tzlist);

        /*
         * fswAdapter = new ArrayAdapter<String>(this,
         * android.R.layout.simple_spinner_item, fswItems);
         * fswAdapter.setDropDownViewResource
         * (android.R.layout.simple_spinner_dropdown_item);
         */
        fswAdapter1 = new FswAdapter(this);
        List<CmsFeature> fswlist = ZSApplication.getDaoSession("zyspps-db").getCmsFeatureDao().queryBuilder()
                .where(com.gesee.zyspps.db.CmsFeatureDao.Properties.SubCodes.like("%" + mapNo + "%"), com.gesee.zyspps.db.CmsFeatureDao.Properties.FiledName.eq("附属物"))
                .orderAsc(com.gesee.zyspps.db.CmsFeatureDao.Properties.Sort).list();
        sp_fsw.setAdapter(fswAdapter1);
        fswAdapter1.addData(fswlist);

        for (int i = 0; i < tzlist.size(); i++)
        {
            if (tzlist.get(i).getFiledValue().equals(pointsList.get(0).getFeature()))
            {
                sp_tezheng.setSelection(i);
            }
        }

        /*
         * fswAdapter = new ArrayAdapter<String>(this,
         * android.R.layout.simple_spinner_item, fswItems);
         * fswAdapter.setDropDownViewResource
         * (android.R.layout.simple_spinner_dropdown_item);
         * sp_fsw.setAdapter(fswAdapter);
         */
        for (int i = 0; i < fswlist.size(); i++)
        {
            if (fswlist.get(i).getFiledValue().toString().equals(pointsList.get(0).getSubsid()))
            {
                sp_fsw.setSelection(i);
            }
        }

        /*jgczAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, jgczItems);
        jgczAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp_jgcz.setAdapter(jgczAdapter);

        for (int i = 0; i < jgczItems.length; i++)
        {
            if (jgczItems[i].toString().equals(pointsList.get(0).getWcover()))
            {
                sp_jgcz.setSelection(i);
            }
        }*/
        List<CmsFeature> jgczlist = ZSApplication.getDaoSession("zyspps-db").getCmsFeatureDao().queryBuilder()
                .where(com.gesee.zyspps.db.CmsFeatureDao.Properties.SubCodes.like("%ALL%"), com.gesee.zyspps.db.CmsFeatureDao.Properties.FiledName.eq("井盖材质"))
                .orderAsc(com.gesee.zyspps.db.CmsFeatureDao.Properties.Sort).list();
        jgczAdapter1 = new FswAdapter(this);
        //jgczAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, jgczItems);
        //jgczAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp_jgcz.setAdapter(jgczAdapter1);
        jgczAdapter1.addData(jgczlist);
        if(jgczlist!=null&&jgczlist.size()>0){
        	for (int i = 0; i < jgczlist.size(); i++)
            {
                if (jgczlist.get(i).getFiledValue().toString().equals(pointsList.get(0).getWcover()))
                {
                    sp_jgcz.setSelection(i);
                }
            }
        }

        /*qsdwAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, qsdwItems);
        qsdwAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp_qsdw.setAdapter(qsdwAdapter);
        for (int i = 0; i < qsdwItems.length; i++)
        {
            if (qsdwItems[i].toString().equals(pointsList.get(0).getBCode()))
            {
                sp_qsdw.setSelection(i);
            }
        }*/
        List<CmsFeature> qsdwlist = ZSApplication.getDaoSession("zyspps-db").getCmsFeatureDao().queryBuilder()
                .where(com.gesee.zyspps.db.CmsFeatureDao.Properties.SubCodes.like("%ALL%"), com.gesee.zyspps.db.CmsFeatureDao.Properties.FiledName.eq("权属单位"))
                .orderAsc(com.gesee.zyspps.db.CmsFeatureDao.Properties.Sort).list();
        qsdwAdapter1 = new FswAdapter(this);
        //qsdwAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, qsdwItems);
        //qsdwAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp_qsdw.setAdapter(qsdwAdapter1);
        qsdwAdapter1.addData(qsdwlist);

        if(qsdwlist!=null&&qsdwlist.size()>0){
        	for (int i = 0; i < qsdwlist.size(); i++)
            {
                if (qsdwlist.get(i).getFiledValue().toString().equals(pointsList.get(0).getBCode()))
                {
                    sp_qsdw.setSelection(i);
                }
            }
        }

        /*ydqkAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ydqkItems);
        ydqkAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp_ydqk.setAdapter(ydqkAdapter);
        for (int i = 0; i < ydqkItems.length; i++)
        {
            if (ydqkItems[i].toString().equals(pointsList.get(0).getSblock()))
            {
                sp_ydqk.setSelection(i);
            }
        }*/
        List<CmsFeature> ydqklist = ZSApplication.getDaoSession("zyspps-db").getCmsFeatureDao().queryBuilder()
                .where(com.gesee.zyspps.db.CmsFeatureDao.Properties.SubCodes.like("%ALL%"), com.gesee.zyspps.db.CmsFeatureDao.Properties.FiledName.eq("淤堵情况"))
                .orderAsc(com.gesee.zyspps.db.CmsFeatureDao.Properties.Sort).list();
        ydqkAdapter1 = new FswAdapter(this);
        //ydqkAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ydqkItems);
        //ydqkAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp_ydqk.setAdapter(ydqkAdapter1);
        ydqkAdapter1.addData(ydqklist);

        sp_tezheng.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                // if (position == 0)
                // {
                LogUtil.d("默认不选中");
                // }
                // else
                // {
                et_tezheng.setText(parent.getItemAtPosition(position).toString());
                // }

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {
                // TODO Auto-generated method stub
   
            }
        });

        sp_fsw.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                // if (position == 0)
                // {
                // LogUtil.d("默认不选中");
                // }
                // else
                // {
                et_fsw.setText(parent.getItemAtPosition(position).toString());
                // }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {
                // TODO Auto-generated method stub

            }
        });

        sp_jgcz.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                // if (position == 0)
                // {
                // LogUtil.d("默认不选中");
                // }
                // else
                // {
                if (parent.getItemAtPosition(position).toString().equals(pointsList.get(0).getWcover()))
                {
                    et_jgcz.setText(parent.getItemAtPosition(position).toString());
                }
                if(flag2){
                    et_jgcz.setText(parent.getItemAtPosition(position).toString());
                }
                flag2 = true;
                //et_jgcz.setText(parent.getItemAtPosition(position).toString());
                // }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {
                // TODO Auto-generated method stub

            }
        });

        sp_qsdw.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                // if (position == 0)
                // {
                // LogUtil.d("默认不选中");
                // }
                // else
                // {
                if (parent.getItemAtPosition(position).toString().equals(pointsList.get(0).getBCode()))
                {
                    et_qsdw.setText(parent.getItemAtPosition(position).toString());
                }
                if(flag){
                    et_qsdw.setText(parent.getItemAtPosition(position).toString());
                }
                flag = true;
                Log.e("result", flag+"");
                // }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {
                // TODO Auto-generated method stub

            }
        });

        sp_ydqk.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                // if (position == 0)
                // {
                // LogUtil.d("默认不选中");
                // }
                // else
                // {
                if (parent.getItemAtPosition(position).toString().equals(pointsList.get(0).getSblock()))
                {
                    et_ydqk.setText(parent.getItemAtPosition(position).toString());
                }
                if(flag1){
                    et_ydqk.setText(parent.getItemAtPosition(position).toString());
                }
                
                flag1 = true;
                Log.e("result", flag+"");
                // }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {
                // TODO Auto-generated method stub

            }
        });
    }

    @Override
    public void onClick(View v)
    {
        // TODO Auto-generated method stub
        switch (v.getId())
        {
        // 确定
        case R.id.btnAccept:
            String mapName = et_gdbh.getText().toString();
            
            if (StringUtil.isEmpty(mapName))
            {
                ToastUtil.show(context, "管点编号不能为空");
                break;
            }
            
            if (mapName.length() == 1)
            {
                ToastUtil.show(context, "无效管点编号");
                break;
            }
            
            String pCodeStr = mapName.substring(0,2);
            
            if (!pCodeStr.equals(pCode))
            {
                ToastUtil.show(context, "不能修改点的类型~");
                break;
            }
            
            String mapD_X = et_xzuobiao.getText().toString();
            String mapD_Y = et_yzuobiao.getText().toString();
            String tezheng = et_tezheng.getText().toString();
            String fsw = et_fsw.getText().toString();
            String jdms = et_jdms.getText().toString();
            String jggg = et_jggg.getText().toString();
            String jgcz = et_jgcz.getText().toString();
            // String jgcc = et_jgcc.getText().toString();
            String jtsd = et_jtsd.getText().toString();
            String jscc = et_jscc.getText().toString();
            String qsdw = et_qsdw.getText().toString();
            String dlmc = et_dlmc.getText().toString();
            String jslx = et_jslx.getText().toString();
            String tcsss = et_tcsss.getText().toString();
            String tcsns = et_tcsns.getText().toString();
            String jcjdj = et_jcjdj.getText().toString();
            String jcjzpbh = et_jcjzpbh.getText().toString();
            
            String bz = et_bz.getText().toString();
            String ydqk = et_ydqk.getText().toString();
            
            String mapNameNum[] = mapName.split(pCode);  
            String MapNoNum = mapNameNum[1];

            String dbName = ZSApplication.getInstance().getConfig("newDBName");
            long updateId = 0;
            List<CmsPoints> list = ZSApplication.getDaoSession(dbName).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(mapName)).build().list();

            for (int i = 0; i < list.size(); i++)
            {
                updateId = list.get(i).getId();
            }

            if (list.size() > 0 && id != updateId)
            {
                ToastUtil.show(context, "管点编号已存在,请重新输入");
                break;
            }
            
            if(MapNoNum.indexOf("—")!=-1){
                MapNoNum = MapNoNum.substring(0,MapNoNum.indexOf("—"));
            }

            CmsPoints points = new CmsPoints();

            points.setId(id);
            points.setExpNO(mapName);
            points.setPCode(mapNo);
            try {
            	points.setMapNoNum(Integer.parseInt(MapNoNum));
                points.setD_X(Double.parseDouble(mapD_X));
                points.setD_Y(Double.parseDouble(mapD_Y));
                points.setFeature(tezheng);
                points.setSubsid(fsw);
                points.setWDeep(jdms);
                points.setMtype(jggg);
                points.setWcover(jgcz);
                points.setWdepth(jtsd);
                points.setHsize(jscc);
                points.setBCode(qsdw);
                points.setRoadName(dlmc);
                points.setJslx(jslx);
                points.setTcsns(tcsns);
                points.setTcsss(tcsss);
                points.setJcjdj(jcjdj);
                points.setJcjzpbh(jcjzpbh);
                /*points.setCableLines(dlts);
                points.setUseHole(yyks);
                points.setTotalHole(zks);*/
                points.setRemark(bz);
                points.setSblock(ydqk);

                List<CmsLine> lineList1 = ZSApplication.getDaoSession(dbName).getCmsLineDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsLineDao.Properties.S_Point.eq(expNo)).build().list();
                
                for (int i = 0; i < lineList1.size(); i++)
                {
                    CmsLine line = new CmsLine();
                    line.setId(lineList1.get(i).getId());
                    line.setS_Point(mapName);
                    line.setE_Point(lineList1.get(i).getE_Point());
                    line.setS_Deep(lineList1.get(i).getS_Deep());
                    line.setE_Deep(lineList1.get(i).getE_Deep());
                    line.setS_D(lineList1.get(i).getS_D());
                    line.setE_D(lineList1.get(i).getE_D());
                    line.setMaterial(lineList1.get(i).getMaterial());
                    line.setDType(lineList1.get(i).getDType());
                    line.setDSize(lineList1.get(i).getDSize());
                    line.setVoltage(lineList1.get(i).getVoltage()); //电压压力
                    line.setDirection(lineList1.get(i).getDirection());
                    line.setRoad(lineList1.get(i).getRoad());
                    line.setRemark(lineList1.get(i).getRemark());
                    ZSApplication.getDaoSession(dbName).getCmsLineDao().updateInTx(line);
                }

                List<CmsLine> lineList2 = ZSApplication.getDaoSession(dbName).getCmsLineDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsLineDao.Properties.E_Point.eq(expNo)).build().list();
                
                for (int i = 0; i < lineList2.size(); i++)
                {
                    CmsLine line = new CmsLine();
                    line.setId(lineList2.get(i).getId());
                    line.setS_Point(lineList2.get(i).getS_Point());
                    line.setE_Point(mapName);
                    line.setS_Deep(lineList2.get(i).getS_Deep());
                    line.setE_Deep(lineList2.get(i).getE_Deep());
                    line.setS_D(lineList2.get(i).getS_D());
                    line.setE_D(lineList2.get(i).getE_D());
                    line.setMaterial(lineList2.get(i).getMaterial());
                    line.setDType(lineList2.get(i).getDType());
                    line.setDSize(lineList2.get(i).getDSize());
                    line.setVoltage(lineList2.get(i).getVoltage()); //电压压力
                    line.setDirection(lineList2.get(i).getDirection());
                    line.setRoad(lineList2.get(i).getRoad());
                    line.setRemark(lineList2.get(i).getRemark());
                    ZSApplication.getDaoSession(dbName).getCmsLineDao().updateInTx(line);
                }

                ZSApplication.getInstance().setConfig("mapCurrentName", mapName);
                ZSApplication.getInstance().setConfig("mapCurrentD_X", mapD_X);
                ZSApplication.getInstance().setConfig("mapCurrentD_Y", mapD_Y);
                ZSApplication.getInstance().setConfig("mapCurrentfsw", fsw);
                ZSApplication.getDaoSession(dbName).getCmsPointsDao().updateInTx(points);

                ZSApplication.getInstance().finishActivity();
			} catch (Exception e) {
				// TODO: handle exception
				ToastUtil.show(context, "物探点号后面只能跟数字");
			}
            

            break;
        // 取消
        case R.id.btnCancel:
            ZSApplication.getInstance().setConfig("mapCurrentName", et_gdbh.getText().toString());
            ZSApplication.getInstance().setConfig("mapCurrentD_X", D_X);
            ZSApplication.getInstance().setConfig("mapCurrentD_Y", D_Y);
            ZSApplication.getInstance().finishActivity();
            break;

        default:
            break;
        }
    }
    
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        
        if (keyCode == KeyEvent.KEYCODE_BACK
                 && event.getRepeatCount() == 0) {
            //do something...
            ZSApplication.getInstance().setConfig("mapCurrentName", et_gdbh.getText().toString());
            ZSApplication.getInstance().setConfig("mapCurrentD_X", D_X);
            ZSApplication.getInstance().setConfig("mapCurrentD_Y", D_Y);
            ZSApplication.getInstance().finishActivity();
             return true;
         }
         return super.onKeyDown(keyCode, event);
     }
    
}
